// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    public class SqlCharacters
    {
        protected static IDictionary<string, SqlCharacters> _members
            = new Dictionary<string, SqlCharacters>(StringComparer.OrdinalIgnoreCase);

        protected string _name;

        protected SqlCharacters(string name)
        {
            this.Register(name);
        }

        protected virtual void Register(string name)
        {
            if (!_members.ContainsKey(name))
            {
                _members.Add(name, this);
            }

            _name = name;
        }

        public static SqlCharacters Parse(string value)
        {
            if (_members.ContainsKey(value))
            {
                return _members[value];
            }

            return NOTHING;
        }

        public static bool IsCharacter(string value)
        {
            return _members.ContainsKey(value);
        }

        public override string ToString()
        {
            return _name;
        }

        public static readonly SqlCharacters NOTHING = new SqlCharacters(String.Empty);

        public static readonly SqlCharacters Comma = new SqlCharacters(",");
        public static readonly SqlCharacters Semicolon = new SqlCharacters(";");
        public static readonly SqlCharacters OpenParentheses = new SqlCharacters("(");
        public static readonly SqlCharacters CloseParentheses = new SqlCharacters(")");
        public static readonly SqlCharacters OpenBraces = new SqlCharacters("{");
        public static readonly SqlCharacters CloseBraces = new SqlCharacters("}");
        public static readonly SqlCharacters Space = new SqlCharacters(" ");
        public static readonly SqlCharacters Tab = new SqlCharacters("\t");
        public static readonly SqlCharacters CarriageReturn = new SqlCharacters("\r");
        public static readonly SqlCharacters LineFeed = new SqlCharacters("\n");
        public static readonly SqlCharacters Period = new SqlCharacters(".");
    }
}
